package com.wnxy.sdd.controller;

import com.wnxy.sdd.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "登录认证")
@RequestMapping("/user")
@Slf4j
public class LoginController {

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody Map<String,String> map){
        String username = map.get("username");
        String password = map.get("password");
        log.info("登录用户：{},密码：{}",username,password);
        // 构造返回数据
        Map<String,String> result = new HashMap<>();
        result.put("token",username);
        return Result.ok(result);
    }

    @ApiOperation("显示用户信息")
    @GetMapping("/info")
    public Result getInfo(String token){
        log.info("用户token：",token);
        // 构造返回数据
        Map<String,Object> result = new HashMap<>();
        result.put("name",token);
        result.put("roles",new String[]{"普通用户"});
        result.put("avatar","https://woniu-demo.oss-cn-shenzhen.aliyuncs.com/fad606282a0042bd951c07a9747390a9.jpg");
        return Result.ok(result);
    }

    @ApiOperation("退出")
    @PostMapping("/logout")
    public Result logout(){
        return Result.ok();
    }
}
